﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Kenh14Embed.ascx.cs" Inherits="GUI.Controls.Embed.Kenh14Embed" %>
<div class="k14embed-wrapper" style="display: none;">
    <div class="tophr clearfix mgt30"></div>
    <div class="wp w980 clearfix">
        <div class="clearfix k14embed mgt20">
            <div class="k14embed-header clearfix">
                <h2><a href="http://kenh14.vn?utm_source=Soha&utm_medium=SohaEmbed&utm_campaign=SohaBoxEmbed" rel="nofollow" target="_blank">Tin tức từ kenh14.vn</a></h2>
                <div class="k14embed-nav">
                    <label class="k14embed-nav-pre"></label>
                    <span>1/3</span>
                    <label class="k14embed-nav-next"></label>
                </div>
            </div>

            <ul>
                
            </ul>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(".k14embed ul").each(function () {
        var base = $(this);
        $.getJSON("http://kenh14.vn/Ajax/NewsSohaEmbed.ashx?callback=?", function(response) {
            bindData(response);
        });

        function bindData(data) {
            var html = '';
            for (var i = 0; i < data.length; i++) {
                var news = data[i];
                html += String.format("<li><a href=\"{0}\" target=\"_blank\"><img src=\"{2}\"></a><a class=\"title\" href=\"{0}\"  target=\"_blank\">{1}</a></li>",
                    news.NewsUrl, news.Title, news.ImageUrl);
            }
            base.html(html);
            $('.k14embed-wrapper').show();
            bindDataCallback();
        }
        var bindDataCallback = function () {
            base.find('li').addClass("k14embed-item");
            var k14CurrentIndex = 1;
            var k14NumberOfSlide = Math.ceil(base.find('li').length / 3, 0);
            base.mcgSlider({
                slideItemElement: ".k14embed-item",
                preButton: $(".k14embed-nav-pre"),
                nextButton: $(".k14embed-nav-next"),
                numberOfVisibleSlides: 3,
                duration: 7000,
                onSlideNext: function () {
                    k14CurrentIndex = k14CurrentIndex >= k14NumberOfSlide ? 1 : k14CurrentIndex + 1;
                    $(".k14embed-nav span").text(k14CurrentIndex + "/" + k14NumberOfSlide);
                },
                onSlideBack: function () {
                    k14CurrentIndex = k14CurrentIndex <= 1 ? k14NumberOfSlide : k14CurrentIndex - 1;
                    $(".k14embed-nav span").text(k14CurrentIndex + "/" + k14NumberOfSlide);
                }
            });
        };
    });
</script>
